<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\Resource;

class Article extends Resource
{

    private $status = '1';
    private $message = 'success';
    public function toArray($request)
    {
        if(method_exists($this, $request->method) && $method = $request->method){
            return $this->$method();
        }
        $this->status = 'failed';
        $this->code = '404';
    }

    public function getItems(){
        return [
            'id'=>$this->id,
            'title'=>$this->title,
            'image'=>$this->image,
            'update'=> 0,
        ];
    }

    public function getInfo(){
        return [
            'id' => $this->id,
            'type' => '7',
            'title' => $this->title,
            'url'=> $this->url,
            'style'=>$this->style,
            'cat_id1'=>new Cat($this->catid1),
            'cat_id2'=>new Cat($this->catid2),
            'style'=>new Cat($this->cstyle),
            'viewnum'=>$this->viewnum,
            'collecnum'=>$this->collecnum,
            'downnum'=>$this->downnum,
            'type'=>$this->type,
            'content'=>$this->content,
            'created_at'=>$this->created_at->toDateString(),
            'update'=> 0,
        ];
    }

    public function with($request){
        return [
            'status' => $this->status,
            'message'   => $this->message,
        ];
    }
}
